Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: improve rust bindings compat #395

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

feat: improve rust bindings compat #395

wants to merge 2 commits into from

Conversation

enitrat
Copy link
Collaborator

@enitrat enitrat commented Jan 10, 2025

improve rust bindings compat, enabling syntaxes like

  • segments.memory.get(idx)
    or
  • dict_trackers[idx] = X

based on a custom fork of the cairo vm in which I unbotherly created a special DictKey type which is an
enum

#[derive(
    Eq, Ord, Hash, PartialEq, PartialOrd, Clone, Debug,
)]
pub enum DictKey {
    Simple(MaybeRelocatable),
    Compound(Vec<MaybeRelocatable>),
}

Which allows a Vec of Felts / Relocatable to be used as dict keys. For us this is important because we need to track preimages that might not fit in a felt inside the dict tracker.

This was implemented in a "dumb" way that is unconsidering of external side effects to the Cairo-VM - once synced with LC we will want to revisit the approach. see https://github.com/kkrt-labs/cairo-vm/tree/kkrt-compat

@enitrat enitrat marked this pull request as ready for review January 10, 2025 18:45
@enitrat enitrat changed the title feat: rust-api compat feat: improve rust-api compat Jan 10, 2025
@enitrat enitrat changed the title feat: improve rust-api compat feat: improve rust bindings compat Jan 10, 2025
@enitrat enitrat requested a review from ClementWalter January 10, 2025 18:48
#[pymethods]
impl PyMemoryWrapper {
fn get(&self, key: PyRelocatable) -> Option<PyMaybeRelocatable> {
unsafe { (*self.runner).vm.get_maybe(&key.inner).map(PyMaybeRelocatable::from) }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why unsafe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants